package map;

import java.util.ArrayList;
import java.util.List;

public class MapChunk {

	private MapTile[][] tiles = new MapTile[20][20];
	private byte index;
	
	private MapChunk() {}
	private MapChunk(byte index) {
		this.index = index;
	}

	public void draw() {
		for(MapTile[] tilez:tiles) {
			for(MapTile tile:tilez) {
				tile.draw();
			}
			System.out.println();
		}
	}
	
	public static MapChunk load(byte[] data) {
		MapChunk loaded=new MapChunk(data[0]);
		int count = 1;
		for(int i=0;i<loaded.tiles.length;i++) {
			MapTile[] tilez=loaded.tiles[i];
			for(int j=0;j<20;j++) {
				tilez[j]=new MapTile(Terrain.get(data[count++]));
			}
		}
		return loaded;
	}
	
	public List<MapTile> getTilesAsList() {
		List<MapTile> list = new ArrayList<>();
		for(MapTile[] tilez:tiles) {
			for(MapTile tile:tilez) {
				list.add(tile);
			}
		}
		return list;
	}
	
	byte getIndex() {
		return this.index;
	}

}
